///PHILOTES Source Code.  (C)2012 PhiloLabs
#pragma once


#ifndef __Bone_H__
#define __Bone_H__

#include "OgrePrerequisites.h"
#include "OgreNode.h"


namespace Ogre 
{
    class _OgreExport Bone : public Node
    {
    public:
        
        Bone(unsigned short handle, Skeleton* creator);
        
        Bone(const String& name, unsigned short handle, Skeleton* creator);
        ~Bone();

        
        Bone* createChild(unsigned short handle, 
            const Vector3& translate = Vector3::ZERO, const Quaternion& rotate = Quaternion::IDENTITY);


        
        unsigned short getHandle(void) const;

        
        void setBindingPose(void);

        
        void reset(void);

        
        void setManuallyControlled(bool manuallyControlled);

        
        bool isManuallyControlled() const;

        
        
        void _getOffsetTransform(Matrix4& m) const;

		
		const Vector3& _getBindingPoseInverseScale(void) const { return mBindDerivedInverseScale; }
		
		const Vector3& _getBindingPoseInversePosition(void) const { return mBindDerivedInversePosition; }
		
		const Quaternion& _getBindingPoseInverseOrientation(void) const { return mBindDerivedInverseOrientation; }

		/// @see Node::needUpdate
		void needUpdate(bool forceParentUpdate = false);


    protected:
        /// The numeric handle of this bone
        unsigned short mHandle;

        
        bool mManuallyControlled;

        
        Node* createChildImpl(void);
        
        Node* createChildImpl(const String& name);

        /// Pointer back to creator, for child creation (not smart ptr so child does not preserve parent)
        Skeleton* mCreator;

        /// The inversed derived scale of the bone in the binding pose
        Vector3 mBindDerivedInverseScale;
        /// The inversed derived orientation of the bone in the binding pose
        Quaternion mBindDerivedInverseOrientation;
        /// The inversed derived position of the bone in the binding pose
        Vector3 mBindDerivedInversePosition;
    };

	
	

}

#endif
